package com.library.hibernatejpa.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Book implements Serializable {
	private static final long serialVersionUID = -7342754079669431139L;

	private Integer id;
	private String title;
	private int pages;
	private Publisher publisher;
	private Author author;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	protected void setId(Integer id) {
		this.id = id;
	}

	public int getLengthInSeconds() {
		return pages;
	}

	public void setLengthInSeconds(int lengthInSeconds) {
		this.pages = lengthInSeconds;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
	public Publisher getPublisher() {
		return publisher;
	}

	protected void setPublisher(Publisher publisher) {
		this.publisher = publisher;
	}

	@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
	public Author getAuthor() {
		return author;
	}

	protected void setAuthor(Author author) {
		this.author = author;
	}

	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
